#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <thread>

#define TEST_CNT 10

void fun_read(int fd)
{
    for (int i = 0; i < TEST_CNT; i++)
    {
        int k;
        read(fd, &k, sizeof(k));
    }
}

void fun_write(int fd)
{
    for (int i = 0; i < TEST_CNT; i++)
    {
        int k = 0;
        write(fd, &k, sizeof(k));
    }
}

int main(void)
{
    int fd = open("/dev/read_write_concurrent", O_RDWR);
    if (fd < 0)
    {
        perror("open");
        exit(-1);
    }

    std::thread th_read(fun_read, fd);
    std::thread th_write(fun_write, fd);

    th_read.join();
    th_write.join();

    close(fd);

    return 0;
}